refactor: extract MD statistics as pure functions#7411
Open
lijianing-sudo wants to merge 1 commit into
Open
Conversation
- Add md_statistics.h with MDKineticState, MDStressState, FIREProjection - Add calc_kinetic_state() and calc_stress_state() pure functions - Old interfaces (current_temp, compute_stress) kept as wrappers - Update nhchain.cpp and msst.cpp call sites Co-Authored-By: Person B <person.b@example.com>
Collaborator
|
This refactoring idea is quite interesting. Feel free to move forward with your implementation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reminder
Linked Issue
Fix #... (refactoring #7: extract MD temperature, kinetic energy, and stress statistics as pure functions)
Unit Tests and/or Case Tests for my changes
No new tests are added — the behavioral surface is unchanged. All existing
MODULE_MDtests pass becausecurrent_temp()andcompute_stress()are preserved as thin wrappers that delegate to the new pure functions internally. The floating-point computation paths are identical.What's changed?
Extract temperature, kinetic energy, and stress statistics from the
MD_funcnamespace into pure functions that return explicit structs, instead of writing results through mutable reference parameters.New file:
source/source_md/md_statistics.hMDKineticState— holdskineticandtemperatureMDStressState— holdst_vector(ionic kinetic tensor) andstress(total stress)FIREProjection— reserved for future FIRE refactoring (not used yet)source/source_md/md_func.h#include "md_statistics.h"calc_kinetic_state()andcalc_stress_state()— pure, no side effectssource/source_md/md_func.cppcalc_kinetic_state()andcalc_stress_state()current_temp()becomes a wrapper: callscalc_kinetic_state(), writes back to ref paramscompute_stress()becomes a wrapper: callscalc_stress_state(), assignsstresskinetic_energy()andtemp_vector()are unchangedsource/source_md/nhchain.cpp— 4 call sites updated infirst_half()andsecond_half():source/source_md/msst.cpp— 4 call sites updated insetup()andsecond_half().Backward compatibility:
md_base.cpp,verlet.cpp,run_md.cpp, andmd_func_test.cppstill call the oldcurrent_temp()/compute_stress()interfaces, which continue to work unchanged.Any changes of core modules? (ignore if not applicable)
No. All changes are confined to
source/source_md/.